<template>
  <el-container class="container">
    <el-header style="background: #fefefe">
      <div class="row header">
        <span class="title">后台管理系统</span>
        <span class="logout" @click="logout">退出登录</span>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          style="height: 100%"
          :default-active="route.path"
          router
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item index="/admin/article">
            <el-icon><document /></el-icon>
            <span>文章管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/introduction">
            <el-icon><document /></el-icon>
            <span>学会介绍</span>
          </el-menu-item>
          <el-menu-item index="/admin/personnel">
            <el-icon><setting /></el-icon>
            <span>人员管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view :key="key" />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const key = computed(() => `${String(route.name || route.path)}-${new Date()}`)
const router = useRouter()
const logout = () => {
  window.localStorage.clear()
  router.replace({
    name: 'login',
  })
}
</script>

<style scoped>
.container {
  height: 100vh;
}
.header {
  height: 100%;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px 0 20px;
}
.title {
  font: 700;
  font-size: large;
}
.logout {
  font-size: small;
}
.logout:hover {
  color: blue;
}
</style>
